<!--
 * @Author: chunlai
 * @Date: 2024-08-15 14:24:36
 * @LastEditTime: 2025-08-29 09:01:45
 * @LastEditors: minsheng_insurance_agency_zhoucl
 * @FilePath: \02.bldinsure\src\views\form\components\MultiAssured.vue
 * @Description: 多被保人
-->
<template>
  <div class="insuPage">
    <div class="topSec">
      <div>
        <div class="form-head-name">被保人信息</div>
        <div class="tit_tips">给谁买谁就是被保险人</div>
      </div>
      <div class="flex_ac"></div>
    </div>
    <!-- <div class="tips_txt ftc4">最多可添加{{bbrMaxNum}}个被保人</div> -->
    <div class="userCell" v-for="(item, index) in bbrMultList" :key="index">
      <MultiAssuredItem
        :ref="`multi-bbr${index}`"
        :pindex="index"
      ></MultiAssuredItem>
    </div>
    <div class="addCell" @click="addUserItem()" v-if="addMoreBtn">
      <MsImgIcon name="add" />
      <span class="ft15 ml4 lh_20">添加被保人</span>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import MultiAssuredItem from "./MultiAssuredItem";
export default {
  name: "MultiAssured",
  components: { MultiAssuredItem },
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      bbrApiReg: "infoReg/bbrApiReg",
      bbrMaxNum: "page/bbrMaxNum",
      noticeMode: "page/noticeMode",
      mainInsu_e: "risks/mainInsu",
      channelType: "insert/channelType",
      bbrMultList: "insert/bbrMultList",
    }),
    addMoreBtn() {
      let res = true;
      const numLen = this.bbrMultList.length;
      if (numLen >= this.bbrMaxNum) {
        res = false;
      }
      if (this.channelType == "3") {
        res = false;
      }
      return res;
    },
  },
  watch: {},
  created() {},
  mounted() {},
  methods: {
    async saveForm() {
      let resObj = { status: true };
      const bnfLen = this.bbrMultList.length;
      let breakTips = [];
      for (let index = 0; index < bnfLen; index++) {
        let refname = `multi-bbr${index}`;
        let flag = await this.$refs[refname][0].saveForm();
        if (!flag.status) {
          resObj = flag;
          break;
        } else {
          if (flag.breakTips) {
            breakTips = breakTips.concat(flag.breakTips);
          }
        }
      }
      if (breakTips.length > 0 && resObj.status) {
        resObj.breakTips = breakTips;
      }
      /**网销告知校验*/
      if (resObj.status) {
        if (
          this.bbrApiReg.hasOwnProperty("healthyStatus") &&
          this.noticeMode == "2"
        ) {
          const notPass = this.bbrMultList.find((e) => e.healthyStatus == "0");
          if (notPass) {
            this.$store.commit("common/SET_FIELD_MEAN_CONT", {
              label: `规则校验`,
              desc: `被保险人健康告知不通过，不能进行投保`,
            });
            return { status: false };
          }
        }
      }
      return resObj;
    },
    addUserItem() {
      // 选计划1不能加附加被保人
      const zhuRisk = this.mainInsu_e[0];
      if (
        ["110176", "110194"].includes(zhuRisk.varietyCode) &&
        zhuRisk.planCode === "1"
      ) {
        this.$store.commit("common/SET_FIELD_MEAN_CONT", {
          label: `规则校验`,
          desc: `${zhuRisk.productName}：选计划1不能添加附加被保人。`,
        });
        return;
      }
      this.$store.dispatch("insert/addNewBbr");
    },
  },
};
</script>
<style lang="less" scoped>
@import "../style.less";

.tips_txt {
  padding: 5px;
  text-align: center;
  font-size: 12px;
  background: #ffffff;
}
.topSec {
  padding-bottom: 0;
}
</style>
